﻿using Serilog;
using SqlSugar.Extensions;

namespace WCS_Core_Configuration
{
    /// <summary>
    /// 配置文件格式化
    /// </summary>
    public class AppSettingsConstVars
    {
        #region 全局地址

        #endregion

        #region 数据库
        /// <summary>
        /// 获取数据库连接字符串
        /// </summary>
        public static readonly string DbSqlConnection = AppSettingsHelper.GetContent("ConnectionStrings", "SqlConnection");
        /// <summary>
        /// 获取数据库类型
        /// </summary>
        public static readonly string DbDbType = AppSettingsHelper.GetContent("ConnectionStrings", "DbType");
        #endregion

        #region Cors跨域设置
        public static readonly string CorsPolicyName = AppSettingsHelper.GetContent("Cors", "PolicyName");
        public static readonly bool CorsEnableAllIPs = AppSettingsHelper.GetContent("Cors", "EnableAllIPs").ObjToBool();
        public static readonly string CorsIPs = AppSettingsHelper.GetContent("Cors", "IPs");
        #endregion
        #region HangFire定时任务
        /// <summary>
        /// 登录账号
        /// </summary>
        public static readonly string HangFireLogin = AppSettingsHelper.GetContent("HangFire", "Login");
        /// <summary>
        /// 登录密码
        /// </summary>
        public static readonly string HangFirePassWord = AppSettingsHelper.GetContent("HangFire", "PassWord");
        #endregion

        #region Jwt授权配置

        public static readonly string JwtConfigSecretKey = AppSettingsHelper.GetContent("JwtConfig", "SecretKey") + AppSettingsHelper.GetMachineRandomKey(DbSqlConnection + AppSettingsHelper.GetMACIp(true));
        public static readonly string JwtConfigIssuer = !string.IsNullOrEmpty(AppSettingsHelper.GetContent("JwtConfig", "Issuer")) ? AppSettingsHelper.GetContent("JwtConfig", "Issuer") : AppSettingsHelper.GetHostName();
        public static readonly string JwtConfigAudience = AppSettingsHelper.GetContent("JwtConfig", "Audience");
        #endregion

        #region 支持的自动化设备
        public static readonly string AutoEquipmentType = AppSettingsHelper.GetContent("AutoEquipmentType", "Type");
        public static readonly string AutoEquipmentDis = AppSettingsHelper.GetContent("AutoEquipmentType", "Dis");
        public static readonly string AutoEquipmentCom = AppSettingsHelper.GetContent("CommunicationType");
        #endregion

        #region 支持的自动化设备的协议报文
        private static readonly string DoorProtocolMsgType = string.Join(":", "Door", AppSettingsHelper.GetContent("ProtocolMsgType", "Door"));
        private static readonly string RotateProtocolMsgType = string.Join(":", "Rotate", AppSettingsHelper.GetContent("ProtocolMsgType", "Rotate"));
        private static readonly string LiftProtocolMsgType = string.Join(":","Lift", AppSettingsHelper.GetContent("ProtocolMsgType", "Lift"));
        private static readonly string LineProtocolMsgType = string.Join(":", "Line",AppSettingsHelper.GetContent("ProtocolMsgType", "Line"));
        private static readonly string PalletProtocolMsgType = string.Join(":", "Pallet", AppSettingsHelper.GetContent("ProtocolMsgType", "Pallet"));
        private static readonly string AirShowerProtocolMsgType = string.Join(":", "AirShower", AppSettingsHelper.GetContent("ProtocolMsgType", "AirShower"));
        private static readonly string CargoProtocolMsgType = string.Join(":", "Cargo", AppSettingsHelper.GetContent("ProtocolMsgType", "Cargo"));
        private static readonly string DetectorProtocolMsgType = string.Join(":", "Detector", AppSettingsHelper.GetContent("ProtocolMsgType", "Detector"));
        static List<string> data = new List<string>() {
                                                DoorProtocolMsgType,
                                                RotateProtocolMsgType,
                                                LiftProtocolMsgType,
                                                LineProtocolMsgType,
                                                PalletProtocolMsgType,
                                                AirShowerProtocolMsgType,
                                                CargoProtocolMsgType,
                                                DetectorProtocolMsgType
                                                };
        public static readonly string ProtocolMsgType = string.Join('-', data.ToArray());
        #endregion

        #region RcsToken
        public static readonly string RcsToken = AppSettingsHelper.GetContent("WCSInfo", "RcsToken");
        #endregion

        #region WcsCode/ClientCode
        public static readonly string WcsClientCode = AppSettingsHelper.GetContent("WCSInfo","ClientCode");
        public static readonly string WcsEqCode = AppSettingsHelper.GetContent("WCSInfo","EqCode");
        #endregion

        #region 透传协议支持的报文
        public static readonly string SerialNetMsg = AppSettingsHelper.GetContent("SerialNetMsg");
        #endregion
        /// <summary>
        /// 最低工作电量
        /// </summary>
        public static readonly string ChargeBattery = AppSettingsHelper.GetContent("ChargeBattery");
        /// <summary>
        /// 最低充电电量
        /// </summary>
        public static readonly string LowWorkBattery = AppSettingsHelper.GetContent("LowWorkBattery");

        #region 任务模板编号
        //入库任务-单巷道
        public static readonly string WarehousingTaskSingleRoadway = AppSettingsHelper.GetContent("TaskTypeCode", "WarehousingTaskSingleRoadway");
        //入库任务-转移巷道
        public static readonly string WarehousingTransferRoadway = AppSettingsHelper.GetContent("TaskTypeCode", "WarehousingTransferRoadway");
        //出库任务-单巷道
        public static readonly string OutboundTaskSingleRoadway = AppSettingsHelper.GetContent("TaskTypeCode", "OutboundTaskSingleRoadway");
        //出库任务-转移巷道
        public static readonly string OutboundTaskTransferRoadway = AppSettingsHelper.GetContent("TaskTypeCode", "OutboundTaskTransferRoadway");
        public static readonly string TransportTaskOutbound = AppSettingsHelper.GetContent("TaskTypeCode", "TransportTaskOutbound");
        public static readonly string TransportTaskEmptybox = AppSettingsHelper.GetContent("TaskTypeCode", "TransportTaskEmptybox");
        public static readonly string TransportTask = AppSettingsHelper.GetContent("TaskTypeCode", "TransportTask");
        #endregion

        #region 上层下发的订单类型
        //入库订单类型名
        public static readonly string WarehousingTaskName = AppSettingsHelper.GetContent("TaskTypeName", "WarehousingTask");
        //出库订单类型名
        public static readonly string OutboundTaskName = AppSettingsHelper.GetContent("TaskTypeName", "OutboundTask");
        //潜伏车搬运任务出库
        public static readonly string TransportOutboundTaskName = AppSettingsHelper.GetContent("TaskTypeName", "TransportTaskOutbound");
        //潜伏车搬运任务空箱入库
        public static readonly string TransportEmptyboxTaskName = AppSettingsHelper.GetContent("TaskTypeName", "TransportTaskEmptybox");
        //潜伏车搬运任务出库
        public static readonly string TransportTaskName = AppSettingsHelper.GetContent("TaskTypeName", "TransportTask");
        #endregion

        #region 海康RCSagvCallback接口Method字段对应配置
        //进入巷道
        public static readonly string EnterRoadwayMethod = AppSettingsHelper.GetContent("agvCallback_Method", "EnterRoadway");
        //驶出巷道
        public static readonly string ExitRoadwayMethod = AppSettingsHelper.GetContent("agvCallback_Method", "ExitRoadway");
        //任务完成
        public static readonly string TaskEndMethod = AppSettingsHelper.GetContent("agvCallback_Method", "TaskEnd");
        //到达转运取货点
        public static readonly string ArriveTransferPickPointMethod = AppSettingsHelper.GetContent("agvCallback_Method", "ArriveTransferPickPoint");
        //到达转运放置点
        public static readonly string ArriveTransferPutPointMethod = AppSettingsHelper.GetContent("agvCallback_Method", "ArriveTransferPutPoint");
        //滚筒出库
        public static readonly string RollerOutboundMethod = AppSettingsHelper.GetContent("agvCallback_Method", "RollerOutbound");
        //滚筒入库
        public static readonly string RollerWarehousingMethod = AppSettingsHelper.GetContent("agvCallback_Method", "RolleWarehousing");
        //CTU任务开始请求
        public static readonly string StartTaskMethod = AppSettingsHelper.GetContent("agvCallback_Method", "StartTask");
        //CTU取货申请
        public static readonly string PickGoodsMethod = AppSettingsHelper.GetContent("agvCallback_Method", "PickGoods");
        #endregion

        #region 传送带别名获取
        public static readonly string Line_2 = AppSettingsHelper.GetContent("LineAlias", "Line_2");
        public static readonly string Line_3 = AppSettingsHelper.GetContent("LineAlias", "Line_3");
        #endregion

        #region 区域编号
        public static readonly string Area_1 = AppSettingsHelper.GetContent("AreaCodes", "area_1");
        public static readonly string Area_2 = AppSettingsHelper.GetContent("AreaCodes", "area_2");
        #endregion

        #region 滚筒带默认参数
        public static readonly string Speed = AppSettingsHelper.GetContent("RollerDefaultPara", "Speed");
        public static readonly string Ass = AppSettingsHelper.GetContent("RollerDefaultPara", "Ass");
        public static readonly string Dec = AppSettingsHelper.GetContent("RollerDefaultPara", "Dec");
        public static readonly string LoadTime = AppSettingsHelper.GetContent("RollerDefaultPara", "LoadTime");
        public static readonly string UnloadTime = AppSettingsHelper.GetContent("RollerDefaultPara", "UnloadTime");
        #endregion

        /// <summary>
        /// 光通信通信间隔最长时间
        /// </summary>
        public static readonly string OpticalMaxTime = AppSettingsHelper.GetContent("OpticalMaxTime");
        /// <summary>
        /// 预调度任务等待时间
        /// </summary>
        public static readonly string PreTaskTime = AppSettingsHelper.GetContent("PreTaskTime");

        public static List<T> ReadRoadWayInfos<T>(string key)
        {
            List<T> result = new List<T>();
            try
            {
                return  AppSettingsHelper.GetContents<T>(key);
            }
            catch (Exception ex)
            {
                Log.Error($"读取配置信息异常{ex.Message}");
                return null;
            }
        }

    }
}
